<template>
  <div class="common-page f-c">
    <BackPage title="标签管理" />
    <div class="search-params f-r a-c j-b">
      <el-form inline>
        <el-form-item label="添加时间：">
          <el-date-picker
            v-model="searchParams.timeValue"
            type="datetimerange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" round @click="onSearch">筛选</el-button>
          <el-button round @click="onReset">重置</el-button>
        </el-form-item>
      </el-form>
      <el-form inline>
        <el-form-item>
          <el-button type="primary" @click="onAdd">新增</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="table-box f-g">
      <el-table
        height="100%"
        v-loading="loading"
        stripe
        :data="tableData"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(255, 255, 255, 0.8)"
        @selection-change="onSelect"
      >
        <el-table-column type="index" width="80px" label="序号" align="center" />
        <el-table-column v-for="item in columns" :key="item.prop" :prop="item.prop" :label="item.label" align="center" />
        <el-table-column label="操作" fixed="right" width="100px">
          <template slot-scope="scope">
            <el-button type="text" @click="onDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page-box">
      <el-pagination
        background
        :current-page="pageNo"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalSize"
        @size-change="changePageSize"
        @current-change="changePageNo"
      />
    </div>

    <el-dialog
      title="添加"
      :visible.sync="dialogVisible"
      width="740px"
    >
      <span>
        <el-form ref="formRef" :model="ruleForm" :rules="rules">
          <el-form-item label="标签名称" prop="label">
            <el-input clearable v-model="ruleForm.label" style="width: 559px;">
              <el-option v-for="item in options" :key="item.value" :value="item.value" :label="item.name" />
            </el-input>
          </el-form-item>
        </el-form>
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="onSave">确认</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import crud from '@/mixins/crud'
import { http_tag } from '@/api'
export default {
  name: 'Index',
  mixins: [crud],
  data() {
    return {
      request: http_tag,
      dialogVisible: false,
      searchParams: {
        timeValue: []
      },
      columns: [
        { prop: 'label', label: '标签名称' },
        { prop: 'createBy', label: '添加人' },
        { prop: 'createTime', label: '添加时间' }
      ],
      tableData: [

      ],
      options: [
        { value: 1, name: 'xxx' }
      ],
      ruleForm: {
        label: ''
      },
      rules: {
        label: [{ required: true, message: '不能为空' }]
      }
    }
  },
  methods: {
    onAdd() {
      this.dialogVisible = true
    },
    onSave() {
      this.$refs.formRef.validate(valid => {
        if (valid) {
          http_tag.create({
            ...this.ruleForm
          }).then(res => {
            this.$message.success(res.msg)
            this.dialogVisible = false
            this.onSearch()
          })
        }
      })
    }
  }
}
</script>

<style lang="scss">
</style>
